<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Function template distance()</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Iterator">
<link rel="up" href="../algorithms.html" title="Algorithms">
<link rel="prev" href="../algorithms.html" title="Algorithms">
<link rel="next" href="next_prior.html" title="Function templates next() and prior()">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../algorithms.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../algorithms.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="next_prior.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="iterator.algorithms.distance"></a><a class="link" href="distance.html" title="Function template distance()">Function template <code class="computeroutput"><span class="identifier">distance</span><span class="special">()</span></code></a>
</h3></div></div></div>
<p>
        The <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">iterators</span><span class="special">::</span><span class="identifier">distance</span></code> function template is an adapted
        version of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">distance</span></code> for the Boost iterator <a class="link" href="../concepts/traversal.html" title="Traversal">traversal
        concepts</a>.
      </p>
<h5>
<a name="iterator.algorithms.distance.h0"></a>
        <span class="phrase"><a name="iterator.algorithms.distance.header"></a></span><a class="link" href="distance.html#iterator.algorithms.distance.header">Header</a>
      </h5>
<pre class="programlisting"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">iterator</span><span class="special">/</span><span class="identifier">distance</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<h5>
<a name="iterator.algorithms.distance.h1"></a>
        <span class="phrase"><a name="iterator.algorithms.distance.synopsis"></a></span><a class="link" href="distance.html#iterator.algorithms.distance.synopsis">Synopsis</a>
      </h5>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">&gt;</span>
<span class="keyword">constexpr</span> <span class="keyword">typename</span> <span class="identifier">iterator_difference</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">&gt;::</span><span class="identifier">type</span>
<span class="identifier">distance</span><span class="special">(</span><span class="identifier">Iterator</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span><span class="special">);</span>
</pre>
<h5>
<a name="iterator.algorithms.distance.h2"></a>
        <span class="phrase"><a name="iterator.algorithms.distance.description"></a></span><a class="link" href="distance.html#iterator.algorithms.distance.description">Description</a>
      </h5>
<p>
        Computes the (signed) distance from <code class="computeroutput"><span class="identifier">first</span></code>
        to <code class="computeroutput"><span class="identifier">last</span></code>.
      </p>
<h5>
<a name="iterator.algorithms.distance.h3"></a>
        <span class="phrase"><a name="iterator.algorithms.distance.requirements"></a></span><a class="link" href="distance.html#iterator.algorithms.distance.requirements">Requirements</a>
      </h5>
<p>
        <code class="computeroutput"><span class="identifier">Iterator</span></code> should model <a class="link" href="../concepts/traversal.html#iterator.concepts.traversal.single_pass" title="Single Pass Iterator Concept">Single Pass Iterator</a>.
      </p>
<h5>
<a name="iterator.algorithms.distance.h4"></a>
        <span class="phrase"><a name="iterator.algorithms.distance.preconditions"></a></span><a class="link" href="distance.html#iterator.algorithms.distance.preconditions">Preconditions</a>
      </h5>
<p>
        If <code class="computeroutput"><span class="identifier">Iterator</span></code> models <a class="link" href="../concepts/traversal.html#iterator.concepts.traversal.random_access" title="Random Access Traversal Concept">Random Access Traversal
        Iterator</a>, <code class="computeroutput"><span class="special">[</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span></code> or <code class="computeroutput"><span class="special">[</span><span class="identifier">last</span><span class="special">,</span> <span class="identifier">first</span><span class="special">)</span></code>
        should be valid; otherwise <code class="computeroutput"><span class="special">[</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">)</span></code> should
        be valid.
      </p>
<h5>
<a name="iterator.algorithms.distance.h5"></a>
        <span class="phrase"><a name="iterator.algorithms.distance.complexity"></a></span><a class="link" href="distance.html#iterator.algorithms.distance.complexity">Complexity</a>
      </h5>
<p>
        If <code class="computeroutput"><span class="identifier">Iterator</span></code> models <a class="link" href="../concepts/traversal.html#iterator.concepts.traversal.random_access" title="Random Access Traversal Concept">Random Access Traversal
        Iterator</a>, it takes constant time; otherwise it takes linear time.
      </p>
<h5>
<a name="iterator.algorithms.distance.h6"></a>
        <span class="phrase"><a name="iterator.algorithms.distance.notes"></a></span><a class="link" href="distance.html#iterator.algorithms.distance.notes">Notes</a>
      </h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
            This function is not a customization point and is protected against being
            found by argument-dependent lookup (ADL).
          </li>
<li class="listitem">
            This function is <code class="computeroutput"><span class="keyword">constexpr</span></code>
            only in C++14 or later.
          </li>
</ul></div>
<h5>
<a name="iterator.algorithms.distance.h7"></a>
        <span class="phrase"><a name="iterator.algorithms.distance.acknowledgements"></a></span><a class="link" href="distance.html#iterator.algorithms.distance.acknowledgements">Acknowledgements</a>
      </h5>
<p>
        Contributed by Michel Morin.
      </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2003, 2005 David Abrahams Jeremy Siek Thomas
      Witt<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at &lt;ulink url="http://www.boost.org/LICENSE_1_0.txt"&gt;
        http://www.boost.org/LICENSE_1_0.txt &lt;/ulink&gt;)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../algorithms.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../algorithms.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="next_prior.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
